<template>
    <div>
        <cmsTitle no-back />
        <el-row style="margin-top:10px" :gutter="10">
            <el-col :md="12">
                <el-card>
                    <!-- 用户分级 -->
                    <groupLevel id="level" :value="data.level" @click="Click" />
                </el-card>
                <!--                 <el-card>
                    <p>--新增--</p>
                    <el-button class="right" size="small" @click="Log()">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save()">保存</el-button>
                    <h2>人脉、内容推荐全局设置</h2>
                    <div class="content">
                        <div class="betwe">
                            <group :value.sync="data.recommend.entrepreneur">创业者</group>
                            <group :value.sync="data.recommend.investor">投资人</group>
                            <group :value.sync="data.recommend.server">服务商</group>
                        </div>
                        <div class="betwe">
                            <group :value.sync="data.recommend.worker">上班族</group>
                            <group :value.sync="data.recommend.student">在校生</group>
                            <group :value.sync="data.recommend.other">未认证</group>
                        </div>
                    </div>
                </el-card> -->
                <el-card v-if="data.ai" id="ai">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>AI数据设置</h2>
                    <div class="content">
                        <div class="flex">
                            <p>默认增加点赞最小数: <ipt v-model="data.ai[0].paramValue" /></p>
                            <p>默认增加点赞同步增加浏览量: <ipt v-model="data.ai[1].paramValue" /></p>
                        </div>
                    </div>
                </el-card>

                <el-card v-if="data.review" id="review">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>内容人工审核比例设置</h2>
                    <div class="content">
                        <div class="flex">
                            <p>问题: <ipt v-model="data.review[0].paramValue" />%</p>
                            <p>文章: <ipt v-model="data.review[1].paramValue" />%</p>
                            <p>评论: <ipt v-model="data.review[2].paramValue" />%</p>
                            <p>动态: <ipt v-model="data.review[3].paramValue" />%</p>
                            <p>回答: <ipt v-model="data.review[4].paramValue" />%</p>
                        </div>
                    </div>
                </el-card>
                <el-card v-if="data.topping" id="topping">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>置顶数量设置</h2>
                    <div class="content">
                        <div class="block">
                            <h3>内容推荐</h3>
                            <div class="flex">
                                <p>
                                    {{ data.topping[0].paramName }} <ipt v-model="data.topping[0].paramValue" />
                                </p>
                                <p>{{ data.topping[1].paramName }} <ipt v-model="data.topping[1].paramValue" /></p>
                            </div>
                        </div>
                        <div class="block">
                            <h3>用户推荐</h3>
                            <div class="flex">
                                <p>
                                    {{ data.topping[2].paramName }} <ipt v-model="data.topping[2].paramValue" />
                                </p>
                                <p>{{ data.topping[3].paramName }} <ipt v-model="data.topping[3].paramValue" /></p>
                            </div>
                        </div>
                    </div>
                </el-card>

                <el-card v-if="data.monitor" id="monitor">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>监控设置</h2>
                    <div class="content">
                        <div class="block">
                            <h3>3分钟内禁止登录</h3>
                            <p>{{ data.monitor[0].paramName }}><ipt v-model="data.monitor[0].paramValue" /></p>
                        </div>
                        <div class="block">
                            <h3>自动置灰监控</h3>
                            <div class="flex">
                                <p>24h浏览次数><ipt v-model="data.monitor[1].paramValue" /></p>
                                <p>24h产生内容量><ipt v-model="data.monitor[2].paramValue" /></p>
                            </div>
                        </div>
                        <div class="block">
                            <h3>自动封禁</h3>
                            <div class="flex">
                                <p>24h浏览次数><ipt v-model="data.monitor[3].paramValue" /></p>
                                <p>24h产生内容量><ipt v-model="data.monitor[4].paramValue" /></p>
                            </div>
                        </div>
                        <div class="block">
                            <h3>自动下架并发送短信</h3>
                            <p>24h被举报次数><ipt v-model="data.monitor[5].paramValue" /></p>
                        </div>
                        <div class="block">
                            <h3>通知管理员</h3>
                            <el-checkbox disabled :checked="true" label="王龙" />
                        </div>
                    </div>
                </el-card>

                <el-card v-if="data.warning" id="warning">
                    <!-- 预警设置 -->
                    <el-button data-id="warning" class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button
                        data-id="warning"
                        class="right"
                        type="primary"
                        size="small"
                        @click="Save"
                    >
                        保存
                    </el-button>
                    <h2>预警设置</h2>
                    <div class="content">
                        <div class="block">
                            <h3>砂锅用户</h3>
                            <div class="flex">
                                <p>当日提现额度 ><ipt v-model="data.warning[0].paramValue" />元</p>
                                <p>当月提现额度 ><ipt v-model="data.warning[1].paramValue" />元</p>
                            </div>
                        </div>
                        <div class="block">
                            <h3>砂锅号用户</h3>
                            <div class="flex">
                                <p>当日提现额度 ><ipt v-model="data.warning[2].paramValue" />元</p>
                                <p>当月提现额度 ><ipt v-model="data.warning[3].paramValue" />元</p>
                            </div>
                        </div>
                        <div class="block">
                            <h3>通知管理员</h3>
                            <div class="flex">
                                <el-checkbox disabled :checked="true" label="王龙">王龙</el-checkbox>
                            </div>
                        </div>
                    </div>
                </el-card>

                <!-- <el-card id="reward">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>推荐好友奖励</h2>
                    <div class="content">
                        <p>奖励锅巴值<ipt v-model="data.reward.reward.paramValue" /></p>
                    </div>
                </el-card> -->
            </el-col>
            <el-col :md="12">
                <!-- 权重 -->
                <el-card class="r">
                    <group-a
                        v-for=" (key,name) in weightMap"
                        :id="key"
                        :key="name"
                        :value="data[key]"
                        @clic="Click"
                    >
                        <h2>{{ name }}</h2>
                    </group-a>
                </el-card>
                <!-- 冷却系数 -->
                <el-card class="r">
                    <group-cool id="cooling" :value="data.cooling" @clic="Click"><h2>冷却系数</h2></group-cool>
                </el-card>

                <el-card class="r">
                    <!-- <div class="block">
                        <el-button class="right" size="small" @click="Log">变动日志</el-button>
                        <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                        <h2>人脉自动推荐门槛设置</h2>
                        <div class="content">
                            <div class="flex">
                                <p>贡献度 > <ipt /></p>
                                <p>活跃度 > <ipt /></p>
                                <p>流水号 > <ipt /></p>
                            </div>
                        </div>
                    </div> -->
                    <div v-if="data.autoAttention" id="autoAttention" class="block">
                        <el-button class="right" size="small" @click="Log">变动日志</el-button>
                        <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                        <h2>关注自动推荐门槛设置</h2>
                        <div class="content">
                            <div class="flex">
                                <p>贡献度 > <ipt v-model="data.autoAttention[0].paramValue" /></p>
                                <p>活跃度 > <ipt v-model="data.autoAttention[1].paramValue" /></p>
                                <p>流水号 > <ipt v-model="data.autoAttention[2].paramValue" /></p>
                            </div>
                        </div>
                    </div>
                    <div v-if="data.QAexpert" id="QAexpert" class="block">
                        <el-button class="right" size="small" @click="Log">变动日志</el-button>
                        <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                        <h2>问答专家门槛设置</h2>
                        <div class="content">
                            <div class="flex">
                                <p>回答数 > <ipt v-model="data.QAexpert[0].paramValue" /></p>
                                <p>粉丝数 > <ipt v-model="data.QAexpert[1].paramValue" /></p>
                                <p>被举报数 &lt; <ipt v-model="data.QAexpert[2].paramValue" /></p>
                            </div>
                        </div>
                    </div>
                </el-card>

                <el-card id="initHeat" class="r">
                    <template v-if="data.initHeat">
                        <el-button class="right" size="small" @click="Log">变动日志</el-button>
                        <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    </template>
                    <h2>初始热度值</h2>
                    <div v-if="data.initHeat" class="content">
                        <div class="flex">
                            <p>文章 : <ipt v-model="data.initHeat[0].paramValue" /></p>
                            <p>问题 : <ipt v-model="data.initHeat[1].paramValue" /></p>
                            <p>回答 : <ipt v-model="data.initHeat[2].paramValue" /></p>
                            <p>动态 : <ipt v-model="data.initHeat[3].paramValue" /></p>
                            <p>话题 : <ipt v-model="data.initHeat[3].paramValue" /></p>
                        </div>
                    </div>
                </el-card>

                <el-card v-if="data.original" id="original" class="r">
                    <el-button class="right" size="small" @click="Log">变动日志</el-button>
                    <el-button class="right" type="primary" size="small" @click="Save">保存</el-button>
                    <h2>砂锅号自动开通原创声明</h2>
                    <div class="content">
                        <div class="flex">
                            <p>入驻时间 > <ipt v-model="data.original[0].paramValue" />天</p>
                            <p>总发文章数 > <ipt v-model="data.original[1].paramValue" /></p>
                            <p>被举报数 &lt; <ipt v-model="data.original[2].paramValue" />%</p>
                            <p>累计总浏览量 > <ipt v-model="data.original[3].paramValue" /></p>
                        </div>
                    </div>
                    <br>
                    <p style="color:#aaa800">提醒：修改前请先确认已修改《原创声明须知》文档。</p>
                </el-card>
            </el-col>
        </el-row>
        <el-dialog title="变动日志" :visible.sync="showLog">
            <airlog ref="log" :query="query" />
        </el-dialog>
    </div>
</template>

<script>
/* eslint-disable camelcase */
import airlog from './components/log.vue'
import group from './components/group.vue'
import groupLevel from './components/groupLevel.vue'
import groupCool from './components/groupCool'
import groupA from './components/autoGroupA'
import groupB from './components/groupB.vue'
export default {
    // eslint-disable-next-line vue/no-unused-components
    components: { airlog, group, groupA, groupB, groupLevel, groupCool },
    data () {
        return {
            query: '',
            test: {},
            showLog: false,
            data: {},
            weightMap: {
                砂锅用户贡献度权重: 'contribution',
                砂锅用户活跃度权重: 'active',
                文章热度权重: 'articleHeat',
                问题热度权重: 'questionHeat',
                回答热度权重: 'answerHeat',
                评论热度权重: 'commentHeat',
                动态热度权重: 'dynamicHeat',
                话题热度权重: 'topicHeat'
            }
        }
    },
    created () {
        this.Query()
    },
    methods: {
        ShowLog (id) {
            this.query = id
            this.showLog = true
        },
        Log (e) {
            const target = e.path.find(v => v.id && (v.id !== 'app'))
            this.ShowLog(target.id)
        },
        Click (type, data, id) {
            const operator = {
                save: data => {
                    const loading = this.$loading({ target: document.querySelector('#' + id) })
                    HTTP('保存参数', data).then(_ => this.$message.success('保存成功')).finally(_ => loading.close())
                },
                log: this.ShowLog
            }
            console.log(`%c${type}`, 'color:#494', data)
            operator[type](data)
        },
        Save (e) {
            const target = e.path.find(v => v.id && (v.id !== 'app'))
            const type = target.id
            const loading = this.$loading({ target })
            const _data = this.data[type]
            const data = []
            if (!type) {
                return loading.close()
            }
            for (const item of _data) {
                const { uid, paramType, paramName, paramValue } = item
                data.push({ uid, paramType, paramName, paramValue })
            }
            console.log('%c发送的数据:', 'color:#00BFFF', data)
            HTTP('保存参数', data).then(_ => this.$message.success('保存成功')).finally(_ => loading.close())
        },
        Query () {
            HTTP('参数列表').then(({ data }) => {
                if (!data.monitor) {
                    return
                }
                const _data = {}
                // 分级设置
                _data.level = data.level
                // 冷却设置
                _data.cooling = data.cooling
                // 预警设置
                _data.warning = [...data.warning.sgwarning, ...data.warning.sghwarning]
                {
                // 监控设置 权重
                    const { level, warning, cooling, ..._param } = data
                    for (const key in _param) {
                        _data[key] = _param[key][key]
                    }
                }
                this.data = _data
            })
        }
    }
}
</script>

<style lang="stylus" scoped>
@import './styl/public.styl'
.el-card
    padding 40px 20px
    min-width 357px
    margin-bottom 10px
    // padding-right 0px
    >>> h2
        display inline-block
        font-size 16px
        color #333
        font-weight 550
        margin-bottom 30px
        &::before
            position absolute
            margin-left -20px
            content '● '
            color #227BE3
    >>> .right
        float right
        margin-left 20px
.block
    margin-bottom 20px
    &:last-of-type
        margin-bottom 0
.r
    >>> .block
        margin-bottom 40px
        padding-bottom 40px
        border-bottom solid 1px #ddd
        &:last-of-type
            border-bottom none
            padding-bottom 0
            margin-bottom 0
</style>
